<?php
App::uses('AppController', 'Controller');
/**
 * Medidas Controller
 *
 * @property Medida $Medida
 */
class MedidasController extends AppController {
    
    public $layout = 'pizza';

    public function beforeFilter()
    {
        parent::beforeFilter();
        $this->Auth->allow('*');
    }
/**
 * index method
 *
 * @return void
 */
	public function index() {
		
        $medidas =$this->Medida->find('all', array('recursive'=>0));
		$this->set(compact('medidas'));
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		$this->Medida->id = $id;
		if (!$this->Medida->exists()) {
			throw new NotFoundException(__('Invalid medida'));
		}
		$this->set('medida', $this->Medida->read(null, $id));
	}

/**
 * add method
 *
 * @return void
 */
	public function insertar() {
		if ($this->request->is('post')) {
			$this->Medida->create();
			if ($this->Medida->save($this->request->data)) {
				$this->Session->setFlash(__('The medida ha sido guardada'),'alerts/bueno');
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Error al guardar la medida. Intente de nuevo.'), 'alerts/alert');
			}
		}
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function editar($id = null) {
		$this->Medida->id = $id;
		if (!$this->Medida->exists()) {
			$this->Session->setFlash(__('Medida invalida'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Medida->save($this->request->data)) {
				$this->Session->setFlash(__('La medida fue guardada'), 'alerts/bueno');
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('Error al guardar la medida. Intente de nuevo.'), 'alerts/alert');
			}
		} else {
			$this->request->data = $this->Medida->read(null, $id);
		}
	}

/**
 * delete method
 *
 * @throws MethodNotAllowedException
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		if (!$this->request->is('post')) {
			$this->Session->setFlash(__('Error al guardar la medida. Intente de nuevo.'), 'alerts/alert');
		}
		$this->Medida->id = $id;
		if (!$this->Medida->exists()) {
			$this->Session->setFlash(__('Error al guardar la medida. Intente de nuevo.'), 'alerts/alert');
		}
		if ($this->Medida->delete()) {
			$this->Session->setFlash(__('Medida eliminada'), 'alerts/bueno');
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Error al guardar la medida. Intente de nuevo.'), 'alerts/alert');
		$this->redirect(array('action' => 'index'));
	}
}
